package errors

import (
	"github.com/pkg/errors"
)

// ErrNoRows 返回无记录错误
func ErrNoRows() error {
	return errors.Wrap(&Error{
		Code:    404,
		Reason:  "NOT FOUND",
		Message: "no rows in result set",
	}, "")
}

// IsErrNoRows 判断错误是不是无记录错误
func IsErrNoRows(err error) bool {
	e := &Error{}
	if !errors.As(err, &e) {
		return false
	}
	return e.Code == 404 && e.Reason == "NOT FOUND"
}

type Error struct {
	Code    int32
	Reason  string
	Message string
}

func (e *Error) Error() string {
	return e.Message
}
